<?php
/**
 * Created by PhpStorm.
 * User: adim
 * Date: 2016/8/7
 * Time: 23:21
 */
global $_W,$_GPC;
$id = $_GPC['id'];
$member = m('member')->getMember($id);
$years = array();
$current_year = date('Y');
$year = $_GPC['year'];
$month = $_GPC['month'];
for ($i = $current_year - 10; $i <= $current_year; $i++) {
    $years[] = array('data' => $i, 'selected' => $i == $year);
}
$months = array();
$current_month = date('m');
for ($i = 1; $i <= 12; $i++) {
    $months[] = array('data' => $i, 'selected' => $i == $month);
}

$agentid = intval($_GPC['id']);
$p = p('commission');
$level = 0;
if ($p) {
    $cset = $p->getSet();
    $level = intval($cset['level']);
}
$prtimeStr = date('Y-m');
$prtimeUnix = strtotime($prtimeStr);
$prtoday = strtotime(date("Y-m-d"));
$datas = p('commission') -> agentOrderChart($agentid,$prtimeUnix,$prtoday);

$member = m('member')->getMember($agentid);
$level1_agentids = p('commission')->getCommissionTeam($member['openid'], 1, 0, null,true);
$prtimeStr = date('Y-m');
$prtimeUnix = strtotime($prtimeStr);
$prtoday = strtotime(date("Y-m-d"));
$data3 = p('commission') -> agentChart($level1_agentids,$prtimeUnix,$prtoday);

$data = $datas['data'];
$data2 = $datas['data2'];
if($_GPC['search'] == 1){
    $timeStr1 = $year.'-'.$month;
    $timeUnix1 = strtotime($timeStr1);
    $month2 = $_GPC['month'] + 1;
    $timeStr2 = $year.'-'.$month2;
    $timeUnix2 = strtotime($timeStr2)-1;
    $nowTime = time();
    $data = array();
    $data2 = array();
    if($timeUnix1 <= $nowTime && $nowTime <= $timeUnix2){
        //查询时间为当月
        $timeUnix1 = strtotime($timeStr1);
        $yesterday = strtotime(date("Y-m-d",strtotime("-1 day")));
        $today = strtotime(date("Y-m-d"));


        $datas = p('commission') -> agentOrderChart($agentid,$timeUnix1,$today);
        $data3 = p('commission') -> agentChart($level1_agentids,$timeUnix1,$today);
        $data = $datas['data'];
        $data2 = $datas['data2'];
    }else{
        $timeUnix3 = $timeUnix2 + 1;
        $datas = p('commission') -> agentOrderChart($agentid,$timeUnix1,$timeUnix2);
        $data3 = p('commission') -> agentChart($level1_agentids,$timeUnix1,$timeUnix3);
        $data = $datas['data'];
        $data2 = $datas['data2'];
    }
}

$charttitle = '订单数量图';
$charttitle2 = '订单金额图';
$biaozhun3 = $member['windingstandard'];
$charttitle3 = '粉丝统计图';
$biaozhun = $member['orderstandard'];
$biaozhun2 = $member['ordermoneystandard'];


include $this->template('agent_order_chart');
die;